<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Qwt User&#39;s Guide: qwt_weeding_curve_fitter.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Qwt User&#39;s Guide
   &#160;<span id="projectnumber">6.2.0</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('qwt__weeding__curve__fitter_8cpp_source.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">qwt_weeding_curve_fitter.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">/******************************************************************************</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"> * Qwt Widget Library</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment"> * Copyright (C) 1997   Josef Wilgen</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * Copyright (C) 2002   Uwe Rathmann</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> * This library is free software; you can redistribute it and/or</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment"> * modify it under the terms of the Qwt License, Version 1.0</span></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment"> *****************************************************************************/</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160; </div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="preprocessor">#include &quot;qwt_weeding_curve_fitter.h&quot;</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="preprocessor">#include &quot;qwt_math.h&quot;</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160; </div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="preprocessor">#include &lt;qpainterpath.h&gt;</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="preprocessor">#include &lt;qpolygon.h&gt;</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="preprocessor">#include &lt;qstack.h&gt;</span></div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="preprocessor">#include &lt;qvector.h&gt;</span></div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160; </div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="keyword">class </span>QwtWeedingCurveFitter::PrivateData</div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;{</div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;  <span class="keyword">public</span>:</div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;    PrivateData()</div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;        : <a class="code" href="class_qwt_weeding_curve_fitter.html#a484813f52d921cc5dc57bb6dcf82668d">tolerance</a>( 1.0 )</div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;        , <a class="code" href="class_qwt_weeding_curve_fitter.html#adfffe6d108f7170bafe5cc81379eaef7">chunkSize</a>( 0 )</div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;    {</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;    }</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160; </div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;    <span class="keywordtype">double</span> <a class="code" href="class_qwt_weeding_curve_fitter.html#a484813f52d921cc5dc57bb6dcf82668d">tolerance</a>;</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;    uint <a class="code" href="class_qwt_weeding_curve_fitter.html#adfffe6d108f7170bafe5cc81379eaef7">chunkSize</a>;</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;};</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160; </div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;<span class="keyword">class </span>QwtWeedingCurveFitter::Line</div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;{</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;  <span class="keyword">public</span>:</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;    Line( <span class="keywordtype">int</span> i1 = 0, <span class="keywordtype">int</span> i2 = 0 )</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;        : from( i1 )</div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;        , to( i2 )</div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;    {</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;    }</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160; </div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;    <span class="keywordtype">int</span> from;</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;    <span class="keywordtype">int</span> to;</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;};</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160; </div>
<div class="line"><a name="l00050"></a><span class="lineno"><a class="line" href="class_qwt_weeding_curve_fitter.html#a7deb4d070a329cbdee454023194898a7">   50</a></span>&#160;<a class="code" href="class_qwt_weeding_curve_fitter.html#a7deb4d070a329cbdee454023194898a7">QwtWeedingCurveFitter::QwtWeedingCurveFitter</a>( <span class="keywordtype">double</span> tolerance )</div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;    : <a class="code" href="class_qwt_curve_fitter.html">QwtCurveFitter</a>( <a class="code" href="class_qwt_curve_fitter.html">QwtCurveFitter</a>::Polygon )</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;{</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;    m_data = <span class="keyword">new</span> PrivateData;</div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;    <a class="code" href="class_qwt_weeding_curve_fitter.html#a62c303f6826fef2be7b7bbe82f530680">setTolerance</a>( <a class="code" href="class_qwt_weeding_curve_fitter.html#a484813f52d921cc5dc57bb6dcf82668d">tolerance</a> );</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;}</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160; </div>
<div class="line"><a name="l00058"></a><span class="lineno"><a class="line" href="class_qwt_weeding_curve_fitter.html#abbd30a948fc6974f881678f80a29768c">   58</a></span>&#160;<a class="code" href="class_qwt_weeding_curve_fitter.html#abbd30a948fc6974f881678f80a29768c">QwtWeedingCurveFitter::~QwtWeedingCurveFitter</a>()</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;{</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;    <span class="keyword">delete</span> m_data;</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;}</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160; </div>
<div class="line"><a name="l00076"></a><span class="lineno"><a class="line" href="class_qwt_weeding_curve_fitter.html#a62c303f6826fef2be7b7bbe82f530680">   76</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="class_qwt_weeding_curve_fitter.html#a62c303f6826fef2be7b7bbe82f530680">QwtWeedingCurveFitter::setTolerance</a>( <span class="keywordtype">double</span> tolerance )</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;{</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;    m_data-&gt;tolerance = qwtMaxF( <a class="code" href="class_qwt_weeding_curve_fitter.html#a484813f52d921cc5dc57bb6dcf82668d">tolerance</a>, 0.0 );</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;}</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160; </div>
<div class="line"><a name="l00085"></a><span class="lineno"><a class="line" href="class_qwt_weeding_curve_fitter.html#a484813f52d921cc5dc57bb6dcf82668d">   85</a></span>&#160;<span class="keywordtype">double</span> <a class="code" href="class_qwt_weeding_curve_fitter.html#a484813f52d921cc5dc57bb6dcf82668d">QwtWeedingCurveFitter::tolerance</a>()<span class="keyword"> const</span></div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;<span class="keyword"></span>{</div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;    <span class="keywordflow">return</span> m_data-&gt;tolerance;</div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;}</div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160; </div>
<div class="line"><a name="l00101"></a><span class="lineno"><a class="line" href="class_qwt_weeding_curve_fitter.html#a9f17a819447cba0e733bd71d90ee2766">  101</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="class_qwt_weeding_curve_fitter.html#a9f17a819447cba0e733bd71d90ee2766">QwtWeedingCurveFitter::setChunkSize</a>( uint numPoints )</div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;{</div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;    <span class="keywordflow">if</span> ( numPoints &gt; 0 )</div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;        numPoints = qMax( numPoints, 3U );</div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160; </div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;    m_data-&gt;chunkSize = numPoints;</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;}</div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160; </div>
<div class="line"><a name="l00114"></a><span class="lineno"><a class="line" href="class_qwt_weeding_curve_fitter.html#adfffe6d108f7170bafe5cc81379eaef7">  114</a></span>&#160;uint <a class="code" href="class_qwt_weeding_curve_fitter.html#adfffe6d108f7170bafe5cc81379eaef7">QwtWeedingCurveFitter::chunkSize</a>()<span class="keyword"> const</span></div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;<span class="keyword"></span>{</div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;    <span class="keywordflow">return</span> m_data-&gt;chunkSize;</div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;}</div>
<div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160; </div>
<div class="line"><a name="l00124"></a><span class="lineno"><a class="line" href="class_qwt_weeding_curve_fitter.html#a374b476ce3ea491760ff7d0ccda0fedf">  124</a></span>&#160;QPolygonF <a class="code" href="class_qwt_weeding_curve_fitter.html#a374b476ce3ea491760ff7d0ccda0fedf">QwtWeedingCurveFitter::fitCurve</a>( <span class="keyword">const</span> QPolygonF&amp; points )<span class="keyword"> const</span></div>
<div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;<span class="keyword"></span>{</div>
<div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;    <span class="keywordflow">if</span> ( points.isEmpty() )</div>
<div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;        <span class="keywordflow">return</span> points;</div>
<div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160; </div>
<div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;    QPolygonF fittedPoints;</div>
<div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;    <span class="keywordflow">if</span> ( m_data-&gt;chunkSize == 0 )</div>
<div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;    {</div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;        fittedPoints = simplify( points );</div>
<div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;    }</div>
<div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;    <span class="keywordflow">else</span></div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;    {</div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;        <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i &lt; points.size(); i += m_data-&gt;chunkSize )</div>
<div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;        {</div>
<div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;            <span class="keyword">const</span> QPolygonF p = points.mid( i, m_data-&gt;chunkSize );</div>
<div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;            fittedPoints += simplify( p );</div>
<div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;        }</div>
<div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;    }</div>
<div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160; </div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;    <span class="keywordflow">return</span> fittedPoints;</div>
<div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;}</div>
<div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160; </div>
<div class="line"><a name="l00151"></a><span class="lineno"><a class="line" href="class_qwt_weeding_curve_fitter.html#ad5c04dcd161b8e238c53a753716eff5c">  151</a></span>&#160;QPainterPath <a class="code" href="class_qwt_weeding_curve_fitter.html#ad5c04dcd161b8e238c53a753716eff5c">QwtWeedingCurveFitter::fitCurvePath</a>( <span class="keyword">const</span> QPolygonF&amp; points )<span class="keyword"> const</span></div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;<span class="keyword"></span>{</div>
<div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;    QPainterPath path;</div>
<div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;    path.addPolygon( <a class="code" href="class_qwt_weeding_curve_fitter.html#a374b476ce3ea491760ff7d0ccda0fedf">fitCurve</a>( points ) );</div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;    <span class="keywordflow">return</span> path;</div>
<div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;}</div>
<div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160; </div>
<div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;QPolygonF QwtWeedingCurveFitter::simplify( <span class="keyword">const</span> QPolygonF&amp; points )<span class="keyword"> const</span></div>
<div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;<span class="keyword"></span>{</div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;    <span class="keyword">const</span> <span class="keywordtype">double</span> toleranceSqr = m_data-&gt;tolerance * m_data-&gt;tolerance;</div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160; </div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;    <a class="code" href="class_q_stack.html">QStack&lt; Line &gt;</a> stack;</div>
<div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;    stack.reserve( 500 );</div>
<div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160; </div>
<div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;    <span class="keyword">const</span> QPointF* p = points.data();</div>
<div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;    <span class="keyword">const</span> <span class="keywordtype">int</span> nPoints = points.size();</div>
<div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160; </div>
<div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;    <a class="code" href="class_q_vector.html">QVector&lt; bool &gt;</a> usePoint( nPoints, <span class="keyword">false</span> );</div>
<div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160; </div>
<div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;    stack.push( Line( 0, nPoints - 1 ) );</div>
<div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160; </div>
<div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;    <span class="keywordflow">while</span> ( !stack.isEmpty() )</div>
<div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;    {</div>
<div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;        <span class="keyword">const</span> Line r = stack.pop();</div>
<div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160; </div>
<div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;        <span class="comment">// initialize line segment</span></div>
<div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;        <span class="keyword">const</span> <span class="keywordtype">double</span> vecX = p[r.to].x() - p[r.from].x();</div>
<div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;        <span class="keyword">const</span> <span class="keywordtype">double</span> vecY = p[r.to].y() - p[r.from].y();</div>
<div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160; </div>
<div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160;        <span class="keyword">const</span> <span class="keywordtype">double</span> vecLength = std::sqrt( vecX * vecX + vecY * vecY );</div>
<div class="line"><a name="l00181"></a><span class="lineno">  181</span>&#160; </div>
<div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;        <span class="keyword">const</span> <span class="keywordtype">double</span> unitVecX = ( vecLength != 0.0 ) ? vecX / vecLength : 0.0;</div>
<div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;        <span class="keyword">const</span> <span class="keywordtype">double</span> unitVecY = ( vecLength != 0.0 ) ? vecY / vecLength : 0.0;</div>
<div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160; </div>
<div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;        <span class="keywordtype">double</span> maxDistSqr = 0.0;</div>
<div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160;        <span class="keywordtype">int</span> nVertexIndexMaxDistance = r.from + 1;</div>
<div class="line"><a name="l00187"></a><span class="lineno">  187</span>&#160;        <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = r.from + 1; i &lt; r.to; i++ )</div>
<div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;        {</div>
<div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;            <span class="comment">//compare to anchor</span></div>
<div class="line"><a name="l00190"></a><span class="lineno">  190</span>&#160;            <span class="keyword">const</span> <span class="keywordtype">double</span> fromVecX = p[i].x() - p[r.from].x();</div>
<div class="line"><a name="l00191"></a><span class="lineno">  191</span>&#160;            <span class="keyword">const</span> <span class="keywordtype">double</span> fromVecY = p[i].y() - p[r.from].y();</div>
<div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160; </div>
<div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;            <span class="keywordtype">double</span> distToSegmentSqr;</div>
<div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;            <span class="keywordflow">if</span> ( fromVecX * unitVecX + fromVecY * unitVecY &lt; 0.0 )</div>
<div class="line"><a name="l00195"></a><span class="lineno">  195</span>&#160;            {</div>
<div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;                distToSegmentSqr = fromVecX * fromVecX + fromVecY * fromVecY;</div>
<div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;            }</div>
<div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;            <span class="keywordflow">else</span></div>
<div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;            {</div>
<div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;                <span class="keyword">const</span> <span class="keywordtype">double</span> toVecX = p[i].x() - p[r.to].x();</div>
<div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;                <span class="keyword">const</span> <span class="keywordtype">double</span> toVecY = p[i].y() - p[r.to].y();</div>
<div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;                <span class="keyword">const</span> <span class="keywordtype">double</span> toVecLength = toVecX * toVecX + toVecY * toVecY;</div>
<div class="line"><a name="l00203"></a><span class="lineno">  203</span>&#160; </div>
<div class="line"><a name="l00204"></a><span class="lineno">  204</span>&#160;                <span class="keyword">const</span> <span class="keywordtype">double</span> s = toVecX * ( -unitVecX ) + toVecY * ( -unitVecY );</div>
<div class="line"><a name="l00205"></a><span class="lineno">  205</span>&#160;                <span class="keywordflow">if</span> ( s &lt; 0.0 )</div>
<div class="line"><a name="l00206"></a><span class="lineno">  206</span>&#160;                {</div>
<div class="line"><a name="l00207"></a><span class="lineno">  207</span>&#160;                    distToSegmentSqr = toVecLength;</div>
<div class="line"><a name="l00208"></a><span class="lineno">  208</span>&#160;                }</div>
<div class="line"><a name="l00209"></a><span class="lineno">  209</span>&#160;                <span class="keywordflow">else</span></div>
<div class="line"><a name="l00210"></a><span class="lineno">  210</span>&#160;                {</div>
<div class="line"><a name="l00211"></a><span class="lineno">  211</span>&#160;                    distToSegmentSqr = std::fabs( toVecLength - s * s );</div>
<div class="line"><a name="l00212"></a><span class="lineno">  212</span>&#160;                }</div>
<div class="line"><a name="l00213"></a><span class="lineno">  213</span>&#160;            }</div>
<div class="line"><a name="l00214"></a><span class="lineno">  214</span>&#160; </div>
<div class="line"><a name="l00215"></a><span class="lineno">  215</span>&#160;            <span class="keywordflow">if</span> ( maxDistSqr &lt; distToSegmentSqr )</div>
<div class="line"><a name="l00216"></a><span class="lineno">  216</span>&#160;            {</div>
<div class="line"><a name="l00217"></a><span class="lineno">  217</span>&#160;                maxDistSqr = distToSegmentSqr;</div>
<div class="line"><a name="l00218"></a><span class="lineno">  218</span>&#160;                nVertexIndexMaxDistance = i;</div>
<div class="line"><a name="l00219"></a><span class="lineno">  219</span>&#160;            }</div>
<div class="line"><a name="l00220"></a><span class="lineno">  220</span>&#160;        }</div>
<div class="line"><a name="l00221"></a><span class="lineno">  221</span>&#160;        <span class="keywordflow">if</span> ( maxDistSqr &lt;= toleranceSqr )</div>
<div class="line"><a name="l00222"></a><span class="lineno">  222</span>&#160;        {</div>
<div class="line"><a name="l00223"></a><span class="lineno">  223</span>&#160;            usePoint[r.from] = <span class="keyword">true</span>;</div>
<div class="line"><a name="l00224"></a><span class="lineno">  224</span>&#160;            usePoint[r.to] = <span class="keyword">true</span>;</div>
<div class="line"><a name="l00225"></a><span class="lineno">  225</span>&#160;        }</div>
<div class="line"><a name="l00226"></a><span class="lineno">  226</span>&#160;        <span class="keywordflow">else</span></div>
<div class="line"><a name="l00227"></a><span class="lineno">  227</span>&#160;        {</div>
<div class="line"><a name="l00228"></a><span class="lineno">  228</span>&#160;            stack.push( Line( r.from, nVertexIndexMaxDistance ) );</div>
<div class="line"><a name="l00229"></a><span class="lineno">  229</span>&#160;            stack.push( Line( nVertexIndexMaxDistance, r.to ) );</div>
<div class="line"><a name="l00230"></a><span class="lineno">  230</span>&#160;        }</div>
<div class="line"><a name="l00231"></a><span class="lineno">  231</span>&#160;    }</div>
<div class="line"><a name="l00232"></a><span class="lineno">  232</span>&#160; </div>
<div class="line"><a name="l00233"></a><span class="lineno">  233</span>&#160;    QPolygonF stripped;</div>
<div class="line"><a name="l00234"></a><span class="lineno">  234</span>&#160;    <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i &lt; nPoints; i++ )</div>
<div class="line"><a name="l00235"></a><span class="lineno">  235</span>&#160;    {</div>
<div class="line"><a name="l00236"></a><span class="lineno">  236</span>&#160;        <span class="keywordflow">if</span> ( usePoint[i] )</div>
<div class="line"><a name="l00237"></a><span class="lineno">  237</span>&#160;            stripped += p[i];</div>
<div class="line"><a name="l00238"></a><span class="lineno">  238</span>&#160;    }</div>
<div class="line"><a name="l00239"></a><span class="lineno">  239</span>&#160; </div>
<div class="line"><a name="l00240"></a><span class="lineno">  240</span>&#160;    <span class="keywordflow">return</span> stripped;</div>
<div class="line"><a name="l00241"></a><span class="lineno">  241</span>&#160;}</div>
<div class="ttc" id="aclass_q_stack_html"><div class="ttname"><a href="class_q_stack.html">QStack</a></div><div class="ttdef"><b>Definition:</b> <a href="qwt__plot__zoomer_8h_source.html#l00017">qwt_plot_zoomer.h:17</a></div></div>
<div class="ttc" id="aclass_q_vector_html"><div class="ttname"><a href="class_q_vector.html">QVector</a></div><div class="ttdef"><b>Definition:</b> <a href="qwt__clipper_8h_source.html#l00023">qwt_clipper.h:23</a></div></div>
<div class="ttc" id="aclass_qwt_curve_fitter_html"><div class="ttname"><a href="class_qwt_curve_fitter.html">QwtCurveFitter</a></div><div class="ttdoc">Abstract base class for a curve fitter.</div><div class="ttdef"><b>Definition:</b> <a href="qwt__curve__fitter_8h_source.html#l00021">qwt_curve_fitter.h:22</a></div></div>
<div class="ttc" id="aclass_qwt_weeding_curve_fitter_html_a374b476ce3ea491760ff7d0ccda0fedf"><div class="ttname"><a href="class_qwt_weeding_curve_fitter.html#a374b476ce3ea491760ff7d0ccda0fedf">QwtWeedingCurveFitter::fitCurve</a></div><div class="ttdeci">virtual QPolygonF fitCurve(const QPolygonF &amp;) const override</div><div class="ttdef"><b>Definition:</b> <a href="qwt__weeding__curve__fitter_8cpp_source.html#l00124">qwt_weeding_curve_fitter.cpp:124</a></div></div>
<div class="ttc" id="aclass_qwt_weeding_curve_fitter_html_a484813f52d921cc5dc57bb6dcf82668d"><div class="ttname"><a href="class_qwt_weeding_curve_fitter.html#a484813f52d921cc5dc57bb6dcf82668d">QwtWeedingCurveFitter::tolerance</a></div><div class="ttdeci">double tolerance() const</div><div class="ttdef"><b>Definition:</b> <a href="qwt__weeding__curve__fitter_8cpp_source.html#l00085">qwt_weeding_curve_fitter.cpp:85</a></div></div>
<div class="ttc" id="aclass_qwt_weeding_curve_fitter_html_a62c303f6826fef2be7b7bbe82f530680"><div class="ttname"><a href="class_qwt_weeding_curve_fitter.html#a62c303f6826fef2be7b7bbe82f530680">QwtWeedingCurveFitter::setTolerance</a></div><div class="ttdeci">void setTolerance(double)</div><div class="ttdef"><b>Definition:</b> <a href="qwt__weeding__curve__fitter_8cpp_source.html#l00076">qwt_weeding_curve_fitter.cpp:76</a></div></div>
<div class="ttc" id="aclass_qwt_weeding_curve_fitter_html_a7deb4d070a329cbdee454023194898a7"><div class="ttname"><a href="class_qwt_weeding_curve_fitter.html#a7deb4d070a329cbdee454023194898a7">QwtWeedingCurveFitter::QwtWeedingCurveFitter</a></div><div class="ttdeci">QwtWeedingCurveFitter(double tolerance=1.0)</div><div class="ttdef"><b>Definition:</b> <a href="qwt__weeding__curve__fitter_8cpp_source.html#l00050">qwt_weeding_curve_fitter.cpp:50</a></div></div>
<div class="ttc" id="aclass_qwt_weeding_curve_fitter_html_a9f17a819447cba0e733bd71d90ee2766"><div class="ttname"><a href="class_qwt_weeding_curve_fitter.html#a9f17a819447cba0e733bd71d90ee2766">QwtWeedingCurveFitter::setChunkSize</a></div><div class="ttdeci">void setChunkSize(uint)</div><div class="ttdef"><b>Definition:</b> <a href="qwt__weeding__curve__fitter_8cpp_source.html#l00101">qwt_weeding_curve_fitter.cpp:101</a></div></div>
<div class="ttc" id="aclass_qwt_weeding_curve_fitter_html_abbd30a948fc6974f881678f80a29768c"><div class="ttname"><a href="class_qwt_weeding_curve_fitter.html#abbd30a948fc6974f881678f80a29768c">QwtWeedingCurveFitter::~QwtWeedingCurveFitter</a></div><div class="ttdeci">virtual ~QwtWeedingCurveFitter()</div><div class="ttdoc">Destructor.</div><div class="ttdef"><b>Definition:</b> <a href="qwt__weeding__curve__fitter_8cpp_source.html#l00058">qwt_weeding_curve_fitter.cpp:58</a></div></div>
<div class="ttc" id="aclass_qwt_weeding_curve_fitter_html_ad5c04dcd161b8e238c53a753716eff5c"><div class="ttname"><a href="class_qwt_weeding_curve_fitter.html#ad5c04dcd161b8e238c53a753716eff5c">QwtWeedingCurveFitter::fitCurvePath</a></div><div class="ttdeci">virtual QPainterPath fitCurvePath(const QPolygonF &amp;) const override</div><div class="ttdef"><b>Definition:</b> <a href="qwt__weeding__curve__fitter_8cpp_source.html#l00151">qwt_weeding_curve_fitter.cpp:151</a></div></div>
<div class="ttc" id="aclass_qwt_weeding_curve_fitter_html_adfffe6d108f7170bafe5cc81379eaef7"><div class="ttname"><a href="class_qwt_weeding_curve_fitter.html#adfffe6d108f7170bafe5cc81379eaef7">QwtWeedingCurveFitter::chunkSize</a></div><div class="ttdeci">uint chunkSize() const</div><div class="ttdef"><b>Definition:</b> <a href="qwt__weeding__curve__fitter_8cpp_source.html#l00114">qwt_weeding_curve_fitter.cpp:114</a></div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><b>qwt_weeding_curve_fitter.cpp</b></li>
    <li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1 </li>
  </ul>
</div>
</body>
</html>
